package com.ws.mapper;

import com.ws.domain.User;
import org.apache.ibatis.annotations.*;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 实现客户登录
     * @param username
     * @param password
     * @return
     */
    @Select("select * from users where username = #{username} and password = #{password}")
    User login(@Param("username") String username, @Param("password") String password);
    //查询所有客户信息
    @Select("select * from users")
    List<User> users();

    //添加客户
    @Insert("insert into users values(null, #{username}, #{password}, #{name}, #{phone}, #{address})")
    void userSave(User user);

    //重置客户密码
    @Update("update users set password = #{password} where id = #{id}")
    void userReset(User user);

    //根据ID跳转修改客户信息页面
    @Select("select * from users where id = #{id}")
    User userEdit(int id);

    //修改客户信息
    @Update("update users set username=#{username}, name=#{name}, phone=#{phone}, address=#{address} where id = #{id}")
    void userUpdate(User user);

   //删除客户
   @Delete("delete from users where id = #{id}")
   void userDelete(int id);

    @Select("select * from users limit #{start}, #{size}")
    List<User> userList(@Param("start") int start, @Param("size") int size);

//
    @Select("select count(*) from users")
   int getCount();

    //修改密码
    @Update("update users set password=#{password} where id = #{id}")
    void passwordUpdate(User user);

    /**
     * 根据用户id 查询用户信息
     * @param userId
     * @return
     */
    @Select("select * from users where id = #{userId}")
    User getById(@Param("userId") int userId);
}
